using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.ComponentModel;

namespace CompositeWeb.Extensions.Configuration
{
    /// <summary>
	/// A configuration element to declare service metadata.
	/// </summary>
    public class ServiceConfigurationElement : ConfigurationElement
    {
		/// <summary>
		/// Initializes a new instance of <see cref="ServiceElement"/>.
		/// </summary>
        public ServiceConfigurationElement() : base()
        {
        }

		/// <summary>
		/// Initializes a new instance of <see cref="ServiceElement"/>.
		/// </summary>
		/// <param name="registerAs">The service contract</param>
		/// <param name="type">The type of the service</param>
		public ServiceConfigurationElement(Type registerAs, Type type, string scope)
        {
            base["registerAs"] = registerAs;
            base["type"] = type;
            base["scope"] = scope;
        }

		/// <summary>
		/// Gets or sets the service contract.
		/// </summary>
        [ConfigurationProperty("registerAs", IsRequired = true)]
        [TypeConverter(typeof(TypeNameConverter))]
        public Type RegisterAs
        {
            get { return (Type)base["registerAs"]; }
            set { base["registerAs"] = value; }
        }

		/// <summary>
		/// Gets or sets the service type.
		/// </summary>
        [ConfigurationProperty("type", IsRequired = true)]
        [TypeConverter(typeof(TypeNameConverter))]
        public Type Type
        {
            get { return (Type)base["type"]; }
            set { base["type"] = value; }
        }

        [ConfigurationProperty("scope", IsRequired = false, DefaultValue="Global")]
        public string Scope
        {
            get { return (string)base["scope"]; }
            set { base["scope"] = value; }
        }
    }
}
